package com.example.buildtable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.buildtable.pojo.User;
import com.example.buildtable.service.UserService;
import com.example.buildtable.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    //管理员登录接口
    @Override
    public Map<String, Object> login(User admin) {
        Map<String, Object> map = new HashMap<>();
        //条件处理
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", admin.getUsername());
        User user = userMapper.selectOne(queryWrapper);
        //没有管理员
        if (user == null) {
            map.put("state", "nourse");
        } else {
            //有管理员，判断密码是否正确
            if (user.getPassword().equals(admin.getPassword())) {
                map.put("state", "success");
            } else {
                map.put("state", "error");
            }
        }
        return map;
    }
}
